/**
 * -----------------------------------
 * Copyright (c) 2021-2025
 * All rights reserved, Designed By www.linfengtech.cn
 * 林风社交论坛商业版本请务必保留此注释头信息
 * 商业版授权联系技术客服	 QQ:  3582996245
 * 严禁分享、盗用、转卖源码或非法牟利！
 * 版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.app.controller;

import io.linfeng.common.annotation.NoRepeatSubmit;
import io.linfeng.common.vo.SignResponse;
import io.linfeng.common.vo.SignUserResponse;
import io.linfeng.common.utils.R;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.entity.BillEntity;
import io.linfeng.modules.admin.entity.SignConfigEntity;
import io.linfeng.modules.admin.service.BillService;
import io.linfeng.modules.admin.service.UserSignService;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * 积分签到
 *
 * @author linfeng
 * @email linfengtech001@163.com
 * @date 2022-05-07 15:01:03
 */
@RestController
@RequestMapping("app/sign")
@Api(tags = "移动端——积分签到")
public class AppUserSignController {

    @Autowired
    private UserSignService userSignService;

    @Autowired
    private BillService billService;


    @Login
    @PostMapping("/userInfo")
    @ApiOperation("获取签到用户信息")
    public R userInfo(@ApiIgnore @LoginUser AppUserEntity user){
        SignUserResponse vo=userSignService.getUserInfo(user);
        return R.ok().put("data",vo);
    }

    @Login
    @PostMapping("/sign")
    @ApiOperation("用户签到")
    @NoRepeatSubmit
    public R sign(@ApiIgnore @LoginUser AppUserEntity user){
        int num = userSignService.sign(user);
        return R.ok().put("integral",num);
    }


    @Login
    @GetMapping("/signList")
    @ApiOperation("用户签到信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页页码",paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "limit", value = "每页数量",paramType = "query", dataType = "Integer", required = true)
    })
    public R signList(@ApiIgnore @LoginUser AppUserEntity user,
                      @RequestParam("page") Integer page,
                      @RequestParam("limit") Integer limit){
        List<SignResponse> list=userSignService.getSignList(user.getUid(),page,limit);
        return R.ok().put("data",list);
    }

    @GetMapping("/config")
    @ApiOperation("签到配置")
    public R signConfig(){
        List<SignConfigEntity> list=userSignService.getConfigList();
        return R.ok().put("data",list);
    }

    @Login
    @GetMapping("/integralList")
    @ApiOperation("用户签到积分列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页页码",paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "limit", value = "每页数量",paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "type", value = "类型",paramType = "query", dataType = "Integer", required = true)
    })
    public R integralList(@ApiIgnore @LoginUser AppUserEntity user,
                          @RequestParam("page") Integer page,
                          @RequestParam("limit") Integer limit,
                          @RequestParam("type") Integer type){
        List<BillEntity> list= billService.getIntegralList(user.getUid(),page,limit,type);
        return R.ok().put("data",list);
    }

}
